﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ThoughtWorks.QRCode.Codec;
using System.Drawing;
using System.IO;

namespace GandAInvitaciones
{
    /// <summary>
    /// Summary description for qr
    /// </summary>
    public class qr : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            qrCodeEncoder.QRCodeScale = 2;
            qrCodeEncoder.QRCodeVersion = 8;//hasta 40
            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;

            Bitmap image;
            String data = context.Request["code"];
            String fv = context.Request["fv"];
            image = qrCodeEncoder.Encode("http://m.ganda-invitaciones.com/verificacupon.aspx?code=" + data + "&fv=" + fv);
            byte[] byteArray = new byte[0];
            using (MemoryStream stream = new MemoryStream())
            {
                image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                stream.Close();

                byteArray = stream.ToArray();
            }

            context.Response.ContentType = "image/png";
            context.Response.BinaryWrite(byteArray);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}